
import React, { useEffect, useState } from "react"
import { comRequest } from '../../request'
import { QQTable } from '../QQTable'
import "./index.less";

export const QQitem = ({ code, isSz, type = 'call', searchData }) => {
    const [optionList, setOptionList] = useState([])
    console.log("optionList", optionList)

    const getInfo = async () => {
        console.log("查询商品数据")
        let cecid = isSz ? `0.${code}` : `1.${code}`


        let bdlinfoUrl = `https://97.push2.eastmoney.com/api/qt/stock/get?mspt=1&secid=${cecid}&ut=bd1d9ddb04089700cf9c27f6f7426281&_=1729940692428`
        if (isSz) {
            bdlinfoUrl = `https://42.push2.eastmoney.com/api/qt/stock/get?mspt=1&secid=${cecid}&ut=bd1d9ddb04089700cf9c27f6f7426281&_=1729940692428`
        }


        try {
            const result = await comRequest({
                url: bdlinfoUrl,
            })

            const data = result?.data?.data || {}
            console.log("bdl", data)
            const temL = data?.optionExpireInfo
                ?.map(item => {
                    let date = String(item.date).slice(0, 6)
                    return {
                        date: date
                    }
                })
            setOptionList(temL)
        } catch (error) {
            console.log("error", error)

        }

    }


    useEffect(async () => {
        if (code) {
            getInfo()
        }


    }, [code])


    return <div>
        <div className="hycontainer">
            {code && optionList ? optionList.map(item => {
                return <div className="hycontainer_item" key={item.date}>
                    <h1 className="date">
                        {item?.date}
                    </h1>
                    <QQTable date={item?.date} code={code} isSz={isSz} type={type} searchData={searchData}></QQTable>
                </div>
            }) : null}
        </div>

    </div>
}